package snsdbook.engine.message;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import snsdbook.engine.FileManager;
import util.Util;

public class UploadFileRequest implements MessageInterface {

  private static final long serialVersionUID = 2373160561908795424L;
  private String filename_;
  private String id_;
  private String username_;

  public UploadFileRequest(String filename, String id, String username) {
    filename_ = filename;
    id_ = id;
    username_ = username;
  }
  
  @Override
  public String ProcessAsServer(ObjectInputStream is, ObjectOutputStream os) {
    Util.Send(os, this);
    Util.Receive(is).ProcessAsServer(is, os);
    return "";
  }

  @Override
  public String ProcessAsClient(ObjectInputStream is, ObjectOutputStream os,
      FileManager manager) {
    MessageInterface response = new UploadFileReply(
        username_,
        filename_,
        id_,
        manager.ReadFile(filename_),
        manager.GetModified(filename_));
    response.ProcessAsClient(is, os, manager);
    return "";
  }
  
  @Override
  public String toString() {
    return "UPLOAD FILE REQUEST, FILENAME=" + filename_ + ", ID=" + id_;
  }

}
